package com.ljl.ningwei.common.utils;

import javax.crypto.KeyGenerator;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

public class KeyGeneratorUtil {
    public static String generateBase64Key() throws NoSuchAlgorithmException {
        KeyGenerator keyGen = KeyGenerator.getInstance("HmacSHA256");
        keyGen.init(256); // 对于HS256，使用256位密钥
        byte[] key = keyGen.generateKey().getEncoded();
        return Base64.getEncoder().encodeToString(key);
    }

    public static void main(String[] args) throws NoSuchAlgorithmException {
        System.out.println("生成的Base64密钥: " + generateBase64Key());
    }
}
